package com.itheima.controller;

import com.itheima.domain.User;
import com.itheima.factory.UserFactory;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestDemo {
    /*获取bean对象的三种方式*/
    @Test
    public void test() {

        ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");

        //强转容易出大事
        User user = (User) ac.getBean("User");
        user.eat();

        //配置两个spring路径找不到
        User user1 = ac.getBean(User.class);
        user1.eat();

        //推荐使用
        User user2 = ac.getBean("User", User.class);
        user2.eat();


    }

    @Test
    public void test1() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");

        ((ClassPathXmlApplicationContext) ac).close();

    }

    public void test3(){
     /*   UserFactory userFactory = new UserFactory();
        User user = userFactory.getUser();
        user.eat();*/

        ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
        User user = ac.getBean("user", User.class);
        user.eat();

    }



    }

